package com.piccolo.wrapper.client.component;

import com.piccolo.wrapper.client.callback.LifeCycleCallback;
import com.piccolo.wrapper.client.callback.StepCallback;
import com.piccolo.wrapper.client.component.Overlay.PActivityOverlay;

/**
 * @author Maria Patrickson
 * @version 1.0
 */
public class PActivity 
{
	private PActivityOverlay overlay;
	private StepCallback stepCallback;
	private LifeCycleCallback startedCallback;
	private LifeCycleCallback finishedCallback;

	/**
	 * Creates a new PActivity
	 */
	public PActivity()
	{
		this.stepCallback = new StepCallback(){
			public void execute(double ellapsed) {
				activityStep(ellapsed);
			}};
		this.startedCallback = new LifeCycleCallback(){
			public void execute() {
				activityStarted();
			}};
		this.finishedCallback = new LifeCycleCallback(){
			public void execute() {
				activityFinished();
			}};
		
		this.overlay = PActivityOverlay.create(stepCallback, startedCallback, finishedCallback);
	}

	/**
	 * This method is called after an activity is has finished 
	 * running and the activity has been removed from the PActivityScheduler queue. 
	 * 
	 * <strong>This is an override point.</strong> 
	 */
	protected void activityFinished() {}
	
	/**
	 * This method is called right before an activity is scheduled to start running.
	 * 
	 * <strong>This is an override point.</strong>  
	 */
	protected void activityStarted() {}
	
	/**
	 * This method is called as the activity is running. This is the method that most 
	 * activities override to perform their behavior.
	 * 
	 * <strong>This is an override point.</strong> 
	 * @param elapsedTime
	 */
	protected void activityStep(double elapsedTime) {}
	
	/**
	 * Get the JavaScript object overlay for this object.
	 * @return The JavaScript object overlay for this object.
	 */
	public PActivityOverlay getOverlay() 
	{
		return overlay;
	}
}
